import Vue from "vue";
import VueRouter from "vue-router";
// import Home from "../views/Home.vue";
// import Login from "../views/Login.vue";
// import ManageCar from "../views/ManageCar.vue";
// import ManageUser from "../views/ManageUser.vue";
// import ManageOrder from "../views/ManageOrder.vue";
// import AddCar from "../views/AddCar.vue";
// import UpdateCar from "../views/UpdateCar.vue";
import { Message } from 'element-ui';
Vue.use(VueRouter);

const routes = [
  {
    path: "/test",
    name: "Test",
    component: () => import("../views/Test.vue"),
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("../views/Login.vue"),
  },
  {
    path: "/",
    name: "Home",
    component: () => import("../views/Home.vue"),
    children: [
      { path: "managecar", component: () => import("../views/ManageCar.vue")},
      { path: "manageuser", component: () => import("../views/ManageUser.vue") },
      { path: "updatecar/:id?", component: () => import("../views/UpdateCar.vue"),props:true},
      { path: "manageorder", component: () => import("../views/ManageOrder.vue") },
      { path: "addcar", component: () => import("../views/AddCar.vue") },
    ],
  },
  {
    path: "/about",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});
// 路由前置守卫 判断前端是否携带token进行请求 如果没有携带token 提示先登录
// router.beforeEach((to,form,next)=>{
//   const token  = localStorage.getItem("token")
//   if(!token){
//     Message({
//       message: '请先您先登录!',
//       type: 'warning'
//     });
//     next()
//     router.push('/login')
//     return
//   }else{
//     next()
//   }
// })

export default router;
